package pers.cz.node;

import pers.cz.exception.ErrorCode;
import pers.cz.exception.JefFlowException;

public enum NodeEnum {
    ;

    String nodeName;
    Class<? extends Node> nodeClass;

    NodeEnum(String nodeName, Class<? extends Node> nodeClass) {
        this.nodeName = nodeName;
        this.nodeClass = nodeClass;
    }

    public String getNodeName() {
        return nodeName;
    }

    public Class<? extends Node> getNodeClass() {
        return nodeClass;
    }

    public static Class<? extends Node> getNodeClassByNodeName(String nodeName) {

        NodeEnum nodeTypeEnum = getEnumByNodeName(nodeName);

        if (nodeTypeEnum == null) {
            throw new JefFlowException(ErrorCode.JEF_FLOW_NODE_ENUM_IS_NULL_ERROR, nodeName);
        }
        return nodeTypeEnum.getNodeClass();
    }

    public static Class<? extends Node> getNodeClassByNode(Node node) {

        String nodeName = node.getName();

        return getNodeClassByNodeName(nodeName);
    }

    public static NodeEnum getEnumByNodeName(String nodeName) {
        for (NodeEnum anEnum : values()) {
            if (anEnum.getNodeName().equalsIgnoreCase(nodeName)) {
                return anEnum;
            }
        }
        return null;
    }


}
